<HTML>
	<HEAD>
		<link rel="stylesheet" type="text/css" href="<?=$base?>bud/css/jquery.treeview.css" />
		<link rel="stylesheet" type="text/css" href="<?=$base?>bud/css/screen.css" />
		<link rel="stylesheet" type="text/css" href="<?=$base?>bud/css/comment.css"/>
		<script type="text/javascript" src="<?=$base?>bud/css/jquery.js" ></script>
		<script type="text/javascript" src="<?=$base?>bud/css/jquery.cookie.js"></script>
		<script type="text/javascript" src="<?=$base?>bud/css/jquery.treeview.js"></script>	
		<script type="text/javascript" src="<?=$base?>bud/css/demo.js"></script>
		<script type="text/javascript" src="<?=$base?>bud/css/numericvalidation.js"></script>
		<script type="text/javascript" src="<?=$base?>bud/css/comment.js"></script>
	</HEAD>
<BODY>
	<H2>Budget : <?=$versi;?></H2>	
<?php
	function convert($val){
		if($val>=1){
			return "TRUE";
		}else{
			return;
		}
	}

	function addSeparator($val){
		return number_format($val,2,',','.');
	}


	if($view_option=='yayasan'){
		echo "<div id='flash_message'>";
		echo "<B>Versi sebelumnya</B><HR>";
		foreach ($change as $key=>$val){
			echo $key." : ".$val."<BR>";
		}
		echo "</div>";
		echo '<hr>';

		$template = array(
			'table_open' => '<table border= "1" width="800" class="table">',
			'row_start'  => '<tr>',
			'table_close' => '</table>'
		);
		$this->table->set_template($template);
		$program = "";
		echo '<hr>'.form_open('bud/bud_edit/process_edit/summary', array('name'=>'form_main'));
		echo "<ul>";
		echo "<TABLE class='table' border='1' width='850'>";
		foreach($query->result() as $row){
			$i++;
			if($program != $row->key_bud_m_program){
				echo "</TABLE>";
				echo "<li>".$row->key_bud_m_program." ".$row->name_program."</li><hr>";
				echo "<TABLE class='table' border='1' width='950'>";
			}
			
			echo "<TR>";
				echo "<TD width='600'>".$row->key." ".$row->name_activity."</TD>";
				echo "<TD>".form_input(array('name'=>$row->key.'[total]','value'=>$row->total,'onchange'=>'checkValue(\''.$row->key.'[total]'.'\','.$row->total.');','onkeyup'=>'strip_nonnumeric(this); addSeparator(this)','title'=>$row->total, 'style'=>'text-align:right'));
				echo "<div id='accordion'><dl class='accordion' id='slider$i'><dt>Komentar</dt><dd><span>".form_input($row->key.'[comment]')."</a>.</span></dd></dl></div><script type='text/javascript'>var slider$i=new accordion.slider('slider$i');slider$i.init('slider$i');</script>";
			echo "</TD></TR>";
			$program = $row->key_bud_m_program;
		}
		echo "</TABLE>";
		echo '<input type="submit" value="Save"/>'.'|'.anchor('bud/bud_edit',form_button('cancel','cancel'));
		echo form_close();
		echo "</ul>";
	}else if($view_option=='manager' || $view_option=='admin'){
		echo "<div id='flash_message'>";
		echo "<B>Versi sebelumnya</B><HR>";
		foreach ($change as $key=>$val){
			echo $key." : ".$val."<BR>";
		}
		echo "</div>";
		echo '<hr>';
		echo form_open('bud/bud_edit/process_edit/detail', array('name'=>'form_main'));
	?>
		<ul id="red" class="treeview-red">
			<h3>Program</h3>
			<?php foreach($content as $keyprog=>$valprog):?>
				<li><span><B><?=$keyprog?></B></span><span id="<?=substr($keyprog,0,strpos($keyprog,' '));?>"></span>
					<?php if(is_array($content[$keyprog])):?>
						<ul>
						<h3>Activity</h3>
						<?php foreach($content[$keyprog] as $keyact=>$valact):?>
							<li><span><?=$keyact?></span><span id="<?=substr($keyact,0,strpos($keyact,' '));?>"></span>
								<ul>
									<I><?=$valact->desc_activity?></I>
									<hr>
									<?php
										$table_detail = new MY_Table(); 
										$table_mark = new MY_Table();
										$i++;
										//Set Template

										$templ_detail = array(
											'table_open' => '<table border= "1" height="300" width="500" class="table">',
											'table_close' => '</table>'
										);
										$templ_mark = array(
											'table_open' => '<table border= "1" height="300" width="300" class="table">',
											'table_close' => '</table>'
										);


										//Detail
										$detail_element = array (		
											  '<B>Total</B>'=> "<SPAN id='total:".$valact->key."'>Rp. ".addSeparator($valact->gaji_honor+$valact->barang_tak_habis+$valact->barang_habis+$valact->jasa_honor_ext+$valact->perjalanan)."</SPAN><SPAN id='jumlah:".$valact->key."' style='float:right;'></SPAN>",
											  '--Gaji'=>			form_input(array('name'=>$valact->key.'[gaji_honor]','value'=>$valact->gaji_honor,'onkeyup'=>'strip_nonnumeric(this); checkChange(this); recalculate_total(\''.$valact->key.'\');', 'style'=>'text-align:right', 'title'=>$valact->gaji_honor)),
											  '--Barang Habis'=>	form_input(array('name'=>$valact->key.'[barang_habis]','value'=>$valact->barang_habis,'onkeyup'=>'strip_nonnumeric(this); checkChange(this); recalculate_total(\''.$valact->key.'\');', 'style'=>'text-align:right', 'title'=>$valact->barang_habis)),
											  '--Barang Tak Habis'=>form_input(array('name'=>$valact->key.'[barang_tak_habis]','value'=>$valact->barang_tak_habis,'onkeyup'=>'strip_nonnumeric(this);  checkChange(this); recalculate_total(\''.$valact->key.'\');', 'style'=>'text-align:right', 'title'=>$valact->barang_tak_habis)),
											  '--Perjalanan'=>      form_input(array('name'=>$valact->key.'[perjalanan]','value'=>$valact->perjalanan,'onkeyup'=>'strip_nonnumeric(this);  checkChange(this); recalculate_total(\''.$valact->key.'\');', 'style'=>'text-align:right', 'title'=>$valact->perjalanan)),
											  '--Jasa Lain'=>		form_input(array('name'=>$valact->key.'[jasa_honor_ext]','value'=>$valact->jasa_honor_ext,'onkeyup'=>'strip_nonnumeric(this);  checkChange(this); recalculate_total(\''.$valact->key.'\');', 'style'=>'text-align:right', 'title'=>$valact->jasa_honor_ext)),
											  'Volume'=>$valact->volume,
											  'Sumber'=>$valact->key_bud_r_sumber,
											  'Unit'=>$valact->key_bud_r_unit,
											  'Aktivitas yayasan'=>$valact->key_bud_m_yayasan_activity,
											  'Program'=>$valact->key_bud_m_program,
										);


										$mark_element = array (

												'Januari'=>form_checkbox($valact->key.'[1]', '1', convert($valact->januari)),
												'Februari'=>form_checkbox($valact->key.'[2]', '1', convert($valact->februari)),
												'Maret'=>form_checkbox($valact->key.'[3]', '1', convert($valact->maret)),
												'April'=>form_checkbox($valact->key.'[4]', '1', convert($valact->april)),
												'Mei'=>form_checkbox($valact->key.'[5]', '1', convert($valact->mei)),
												'Juni'=>form_checkbox($valact->key.'[6]', '1', convert($valact->juni)),
												'Juli'=>form_checkbox($valact->key.'[7]', '1', convert($valact->juli)),
												'Agustus'=>form_checkbox($valact->key.'[8]', '1', convert($valact->agustus)),
												'September'=>form_checkbox($valact->key.'[9]', '1', convert($valact->september)),
												'Oktober'=>form_checkbox($valact->key.'[10]', '1', convert($valact->oktober)),
												'November'=>form_checkbox($valact->key.'[11]', '1', convert($valact->november)),
												'Desember'=>form_checkbox($valact->key.'[12]', '1', convert($valact->desember)),			
										);

										$table_detail->set_template($templ_detail);

										foreach($detail_element as $key=>$val){
											$table_detail->add_row('<FONT size="2">'.$key.'</FONT>','<FONT size="2">'.$val.'</FONT>');
										}

										//Mark
										$table_mark->set_template($templ_mark);				
										
										foreach($mark_element as $key=>$val){
											$table_mark->add_row('<FONT size="2">'.$key.'</FONT>','<FONT size="2">'.$val.'</FONT>');
										}
															
									?>
									
									<TABLE border= "4" height="200" width="800" class="table">
										<TR>
											<TD colspan='2' align="CENTER">
												<FONT size="3"><B>Detail Budget</B></FONT>
											</TD>
										</TR>
										<TR>
											<TD>
												<?=$table_detail->generate();?>
											</TD>
											<TD>
												<?=$table_mark->generate();?>
											</TD>
										</TR>
										<TR>
										<TD colspan=2>
											<? echo "<div id='accordion'><dl class='accordion' id='slider$i'><dt>Komentar</dt><dd><span>".form_input($valact->key.'[comment]')."</a>.</span></dd></dl></div><script type='text/javascript'>var slider$i=new accordion.slider('slider$i');slider$i.init('slider$i');</script>";?>
										</TD>
									</TABLE>	

									<?php
										//$table_detail->clear();	
										//$table_mark->clear();
									?>
								</ul>
							</li>
						<?php endforeach;?>
						</ul>
					<?php endif;?>
				</li>
			<?php endforeach;?>
		</ul>
	<?
		echo '<input type="submit" value="Save"/>'.'|'.anchor('bud/bud_edit',form_button('cancel','cancel'));
		echo form_close();
	}else{
		redirect(base_url());								
	}
?>

	
<script language="JavaScript">
	

  var text = "";
  function checkValue(field_name,def){
	field = document.form_main.elements[field_name];
	if(field.value!=def){
		field.style.background = "#FFEE99";
	}else{
		field.style.background = "#FFFFFF";
	}
  }

 function checkChange(that){
	var elements = document.getElementsByTagName('SPAN');
	var i;
	var text;
	
	if(that.value != that.title){
		for (i=0; i<elements.length; i++) {
			if(elements[i].id.length != 0 ){
				if(that.name.indexOf(elements[i].id)==0){
					elements[i].innerHTML= "<IMG SRC=\"http://syp.si.del.ac.id/images/icons/fugue/highlighter.png\">";
				}
			}
		}
	}else{
		for (i=0; i<elements.length; i++) {
			if(elements[i].id.length != 0 ){
				if(that.name.indexOf(elements[i].id)==0){
					elements[i].innerHTML= "";
				}
			}
		}
	}
  }

  function recalculate_total(name) {
		var elements = document.forms[0].elements;
		var i;
		var name;
		var value;

		var total = 0.00;
		document.getElementById("jumlah:"+name).innerHTML = total;
		for (i=0; i<elements.length; i++) {
			if (elements[i].name.indexOf(name)==0) {
				value = parseFloat(elements[i].value);
				if (isNaN(value)) {
					value = 0.00;
				}
				
				total = total + value;
			}
		}
		document.getElementById("jumlah:"+name).innerHTML = "="+(total-12);
  }

</script>
</BODY>
</HTML>
